<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="common">
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
${param.id}
<hr style="color: #2694e8"  >
<form id="myForm">

            <div class="modal-body"  style="background-color: #99cdff">个人信息</div>
            <div class="input-group">
                <span class="input-group-addon" >真实姓名</span>
                <input type="text" class="form-control" id="userName" name="userName">
                <input type="hidden" id="userId" name="userId">
            </div>
            <div class="input-group">
                <span class="input-group-addon">性别</span>
                <input type="radio" name="userSex" value="1" id="nan">男
                 <input type="radio" name="userSex" value="2" id="nv">女
            </div>
            <div class="input-group">
                <span class="input-group-addon">出生日期</span>
                <input type="date" class="form-control" id="userDate" name="userDate" >
            </div>
            <div class="input-group">
                <span class="input-group-addon">身份证号</span>
                <input type="text" class="form-control" id="userCard" name="userCard" readonly>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-lg"  onclick="add()">
                    <span class="glyphicon glyphicon-user"></span> 保存
                </button>
            </div>


</form>
</body>
<script>
    $(function (){
        getByid();
    })

    function getByid() {


        $.ajax({
            url: "../tree/getByid",

            type: "post",
            success: function (data) {
                console.log(data)
                $("#userName").val(data.userName);
                $("#userDate").val(data.userDate);
                $("#userId").val(data.userId);
                $("#userCard").val(data.userCard)
                if (data.userSex == 1) {

                    $("#nan").prop("checked", true);
                } else if (data.userSex == 2) {

                    $("#nv").prop("checked", true);
                }
            }

        })
    }
    //保存
    function  add(){
        alert(2131)
        console.log($("#myForm").serialize())
        $.ajax({
            url:"../tree/updateUser",
            data:$("#myForm").serialize(),
            type:"post",
            success:function (data){
                alert(data);
                getByid();
            }
        })
    }
</script>
</html>